FreeLibrary

FreeLibrary decrements the reference count of the loaded dynamic-link library (DLL) module. When the reference count reaches zero, the module is unmapped from the address space of the calling process and the handle is no longer valid.

Syntax

BOOL FreeLibrary(
    HMODULE hLibModule
);

Parameters

hLibModule

Handle to the loaded library module. The LoadLibrary function returns this handle.

Return Value

TRUE if the function succeeds, FALSE if the function fails

To get extended error information, call GetLastError.

Remarks

Each process maintains a reference count for each loaded library module.

This reference count is incremented each time LoadLibrary is called and is decremented each time FreeLibrary is called. An RTDLL module loaded at process initialization due to load-time dynamic linking has a reference count of one. This count is incremented if the same module is loaded again by a call to LoadLibrary.

Before unmapping a library module, the system enables the RTDLL to detach from the process by calling the RTDLL's DllMain function, if it has one, with the DLL_PROCESS_DETACH value. Doing so gives the RTDLL an opportunity to clean up resources allocated on behalf of the current process. After the entry-point function returns, the library module is removed from the address space of the current process.

It is not safe to call FreeLibrary from DllMain. For more information, see the Comments section in DllMain.

Calling FreeLibrary does not affect other processes using the same library module.

Requirements

Minimum Supported Version RTX64 2013
Header windows.h
Library Rtx_Rtss.lib

See Also:

DllMain

ExitThread

LoadLibrary